import React from 'react';
import CommonList from '../../../components/CommonLists/list';
import { Tooltip, Button } from 'antd';
import { IS_SYSTEM_COM } from '../../../utils/constant';

class ComputeModeList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'computeMode';
    this.editButton = record => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.edit.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT || record.type === 1}
        >
          编辑
        </Button>
      );
    };
    this.delButton = record => {
      return (
        <Button
          size='small'
          type='link'
          disabled={record.audit_status === this.AUDIT._WAIT || record.type === 1}
          onClick={this.delete.bind(this, record)}
        >
          删除
        </Button>
      );
    };
    this.btnGroup = [this.editButton, this.delButton];
  }

  // 删除时的参数
  getDeleteParam = record => {
    return { calculate_type_id: record.calculate_type_id };
  };

  componentDidMount() {}

  refreshTableFilter = params => {
    this.props.refreshTableFilter && this.props.refreshTableFilter(params);
  };

  getColumn = () => {
    return [
      {
        title: '计算方式',
        key: 'calculate_type_name',
        dataIndex: 'calculate_type_name',
        ellipsis: true,
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext'>
                <Button type='link' onClick={() => this.props.showDetail(record)}>
                  {text}
                </Button>
              </div>
            </Tooltip>
          );
        }
      },
      {
        title: 'Code',
        key: 'calculate_type_code',
        dataIndex: 'calculate_type_code',
        render: text => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext'>{text}</div>
            </Tooltip>
          );
        }
      },
      {
        title: (
          <>
            {this.props.getFilterTitle(
              '类型',
              [
                {
                  value: -1,
                  name: '全部'
                },
                {
                  value: IS_SYSTEM_COM._TRUE,
                  name: '系统内置'
                },
                {
                  value: IS_SYSTEM_COM._FALSE,
                  name: '自定义'
                }
              ],
              'type',
              this.refreshTableFilter,
              ['value', 'name']
            )}
          </>
        ),
        key: 'type',
        dataIndex: 'type',
        ellipsis: true,
        render: (text, record) => {
          return <>{record.type === IS_SYSTEM_COM._TRUE ? '系统内置' : '自定义'}</>;
        }
      },
      {
        title: '描述',
        dataIndex: 'remark',
        key: 'remark',
        ellipsis: true,
        width: '20%',
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {text}
              </div>
            </Tooltip>
          );
        }
      },
      {
        title: '创建/修改人',
        dataIndex: 'create_user_name',
        key: 'create_user_name',
        ellipsis: true,
        render: (text, record) => {
          var content = !!record.update_user_name
            ? `${record.create_user_name}/${record.update_user_name}`
            : `${record.create_user_name}/${record.create_user_name}`;
          return (
            <Tooltip title={content} placement='topLeft'>
              <div className='overflowtext'>{content}</div>
            </Tooltip>
          );
        }
      },
      {
        title: '修改时间',
        dataIndex: 'update_time',
        key: 'update_time',
        ellipsis: true,
        render: (text, record) => {
          var content = !!record.update_time ? record.update_time : record.create_time;
          return (
            <Tooltip title={content} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {content}
              </div>
            </Tooltip>
          );
        }
      }
    ];
  };
}

export default ComputeModeList;
